package days48;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class day20 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String str1=scanner.nextLine();
        String str2=scanner.nextLine();
        if (str1.length() > str2.length()) {
            String temp = str1;
            str1 = str2;
            str2 = temp;
        }
        int[][] arr=new int[str1.length()+1][str2.length()+1];
        int max=0;
        int index=0;
        for (int i = 0; i < str1.length(); i++) {
            for (int j = 0; j < str2.length(); j++) {
                if(str1.charAt(i)==str2.charAt(j)){
                    arr[i+1][j+1]=arr[i][j]+1;
                }
                if(max<arr[i+1][j+1]){
                    max=arr[i+1][j+1];
                    index=i+1;
                }
            }
        }
        System.out.println(str1.substring(index-max,index));
    }
    public static void main1(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()) {
            int n=scanner.nextInt();
            if(n<2){
                System.out.println(0);
                return;
            }
            int count=0;
            while (n>=2){
                if(n>2){
                    n-=3;
                    n++;
                    count++;
                    continue;
                }
                if(n==2){
                    count++;
                    break;
                }
            }
            System.out.println(count);
        }

    }
}
